package com.library.service.impl;


import com.library.bean.Book;
import com.library.mapper.BookMapper;
import com.library.service.BookService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BookServiceImpl implements BookService {
    @Resource
    private BookMapper bookMapper;
    @Override
    public List<Book> selectAllBooks() {
        return bookMapper.selectAllBooks();
    }

    @Override
    public int deleteBook(int bookId) {
        return bookMapper.deleteBook(bookId);
    }

    @Override
    public int updateBook(Book book) {
        return bookMapper.updateBook(book);
    }

    @Override
    public Book selectBookById(int bookId) {
        return bookMapper.selectBookById(bookId);
    }

    @Override
    public int insertBook(Book book) {
        if (bookMapper.selectBookByName(book.getBookName())==null){
            return bookMapper.insertBook(book);
        }
        return -1;
    }

    @Override
    public int updateBookCover(String bookName, String bookCover) {
        return bookMapper.updateBookCover(bookName, bookCover);
    }

    @Override
    public List<Book> selectBooksByCondition(Book book, String startDate, String endDate) {
        return bookMapper.findBooksByConditions(book, startDate, endDate);
    }


}
